const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
    service: '163',  //  邮箱
    secure: true,    //  安全的发送模式
    auth: {
        user: 'isfengye@163.com', //  发件人邮箱
        pass: 'FCNESYYDKDJZGXKT' //  授权码
    }
});

// 发送邮件
function sendMail(title, text, email) {
    return new Promise((resolve, reject) => {
        transporter.sendMail(
            {
                // 发件人邮箱
                from: 'isfengye@163.com',
                // 邮件标题
                subject: title,
                // 目标邮箱
                to: email,
                // 邮件内容
                text: text + `</br>——<a href='https://ckck.life'>企鹅视频</a>`
            },
            (err, data) => {
                if (err) {
                    console.log(err, '发送验证码失败')
                    reject('发送验证码失败');
                }
                else {
                    resolve('发送验证码成功');
                }
            }
        );
    });
}

module.exports = {
    sendMail
}